package com.cjh.wxdemoserver.base.config;

import com.cjh.wxdemoserver.base.enums.CommonResultCode;
import com.cjh.wxdemoserver.base.exception.BizException;
import com.cjh.wxdemoserver.base.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author ChenJH
 * @description 全局异常处理
 */

@Slf4j
@Order(0)
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public Result<Void> Exception(Exception e) {
        log.error("未知异常", e);
        return Result.error(CommonResultCode.UNKNOWN_ERROR);
    }

    @ExceptionHandler(value = BizException.class)
    public Result<Void> BizException(BizException e) {
        log.error("业务异常", e);
        return Result.error(e);
    }
}
